//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <asm.h>

.global C_SYMBOL(SaveWMMXRegisters)
.global C_SYMBOL(RestoreWMMXRegisters)

C_SYMBOL(SaveWMMXRegisters):
        tmrc    r12, wCon
        tst     r12, #0x3
        moveq   pc, lr

        and     r12, r12, #0x3
        str     r12, [r1] // Whether WMMX is Used

        tst     r12, #0x1 // Is wCx updated?
        beq     SaveDataRegisters

SaveControlRegisters:
        wstrw   wCSSF, [r0, #0x80]
        wstrw   wCASF, [r0, #0x84]
        wstrw   wCGR0, [r0, #0x88]
        wstrw   wCGR1, [r0, #0x8C]
        wstrw   wCGR2, [r0, #0x90]
        wstrw   wCGR3, [r0, #0x94]

SaveDataRegisters:
        tst     r12, #0x2 // Is wRn updated?
        beq     Clear_wCon
        wstrd   wR0,  [r0, #0x00]
        wstrd   wR1,  [r0, #0x08]
        wstrd   wR2,  [r0, #0x10]
        wstrd   wR3,  [r0, #0x18]
        wstrd   wR4,  [r0, #0x20]
        wstrd   wR5,  [r0, #0x28]
        wstrd   wR6,  [r0, #0x30]
        wstrd   wR7,  [r0, #0x38]
        wstrd   wR8,  [r0, #0x40]
        wstrd   wR9,  [r0, #0x48]
        wstrd   wR10, [r0, #0x50]
        wstrd   wR11, [r0, #0x58]
        wstrd   wR12, [r0, #0x60]
        wstrd   wR13, [r0, #0x68]
        wstrd   wR14, [r0, #0x70]
        wstrd   wR15, [r0, #0x78]
Clear_wCon:
        mov     r12, #3
        tmcr    wCon, r12
        mov     pc, lr

C_SYMBOL(RestoreWMMXRegisters):
        // Load wRn
        wldrd   wR0,  [r0, #0x00]
        wldrd   wR1,  [r0, #0x08]
        wldrd   wR2,  [r0, #0x10]
        wldrd   wR3,  [r0, #0x18]
        wldrd   wR4,  [r0, #0x20]
        wldrd   wR5,  [r0, #0x28]
        wldrd   wR6,  [r0, #0x30]
        wldrd   wR7,  [r0, #0x38]
        wldrd   wR8,  [r0, #0x40]
        wldrd   wR9,  [r0, #0x48]
        wldrd   wR10, [r0, #0x50]
        wldrd   wR11, [r0, #0x58]
        wldrd   wR12, [r0, #0x60]
        wldrd   wR13, [r0, #0x68]
        wldrd   wR14, [r0, #0x70]
        wldrd   wR15, [r0, #0x78]
        // Load wCx
        wldrw   wCSSF, [r0, #0x80]
        wldrw   wCASF, [r0, #0x84]
        wldrw   wCGR0, [r0, #0x88]
        wldrw   wCGR1, [r0, #0x8C]
        wldrw   wCGR2, [r0, #0x90]
        wldrw   wCGR3, [r0, #0x94]
        // Clear wCon
        mov     r12, #3
        tmcr    wCon, r12
        mov     pc, lr
